//
//  FilePathHelper.m
//  MIS Cloud
//
//  Created by goldeney on 13-11-19.
//  Copyright (c) 2013年 goldeneye. All rights reserved.
//

#import "FilePathHelper.h"

@implementation FilePathHelper

+(NSString *)getDocumentPath
{
    //return [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];（不安全，可能以后会有变动）
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}

+(NSString *)getTempPath
{
    NSString *tempPath = NSTemporaryDirectory();
    return tempPath;
}

+ (NSString *)getMailFilePath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"MailFile"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+ (NSString *)getMailSendDraftFilePath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"MailSendDraftFile"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+ (NSString *)getSqliteDBfoPath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"SqliteDB"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+ (NSString *)getUserInfoPath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"UserInfo"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+(NSString *)getTargetFloderPath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"DownLoad"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+(NSString *)getTempFolderPath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"Temp"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

//截图文件夹
+(NSString *)getScreenshotFolderPath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"Screenshot"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+(NSString *)getEnterpriseDiskFolderPath
{
    NSString *filerPath = [[self getDocumentPath] stringByAppendingPathComponent:@"EnterpriseDisk"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+(BOOL)isExistFile:(NSString *)fileName
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    return [fileManager fileExistsAtPath:fileName];
}

+ (void)createFileDirectories:(NSString*)filerPath
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDir = FALSE;
    BOOL isDirExist = [fileManager fileExistsAtPath:filerPath isDirectory:&isDir];
    
    if(!(isDirExist && isDir)) {
        BOOL bCreateDir = [fileManager createDirectoryAtPath:filerPath
                                 withIntermediateDirectories:YES attributes:nil error:nil];
        if(!bCreateDir){
            NSLog(@"Create Audio Directory Failed.");
        }
    }
}

//*********临时缓存目录*********

+(NSString *)getCachePhotosFolderPath
{
    NSString *filerPath = [[self getTempPath] stringByAppendingPathComponent:@"CachePhotos"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+(NSString *)getCachePhotosFolderPathNotCreat
{
    NSString *filerPath = [[self getTempPath] stringByAppendingPathComponent:@"CachePhotos"];
    return filerPath;
}

+(NSString *)getCacheEmailsFolderPath
{
    NSString *filerPath = [[self getTempPath] stringByAppendingPathComponent:@"CacheEmails"];
    [self createFileDirectories:filerPath];
    return filerPath;
}

+(NSString *)getCacheEmailsFolderPathNotCreat
{
    NSString *filerPath = [[self getTempPath] stringByAppendingPathComponent:@"CacheEmails"];
    return filerPath;
}

@end
